const http = require("http")
const route = require("./route");
const api = require("./api")
const Router = {}

// Object.assign(Router,route)
// Object.assign(Router,api)

function use(obj) {
  Object.assign(Router,obj)
}

function start() {
  http.createServer((req, res)=> {
    // favicon
    const myURL = new URL(req.url, "http://127.0.0.1")
    console.log(myURL.pathname)
    try {
      Router[myURL.pathname](res)
    } catch (error) {
      Router["/404"](res)
    }

  }).listen(3000, ()=> {
    console.log("server start")
  })
}

exports.start = start
exports.use = use